<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('编辑合同')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-contract-edit" th:object="${tContract}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">公司名称：</label>
            <div class="col-sm-8">
                <input name="corporateName" class="form-control" type="text" th:value="${tContract.corporateName}" required>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">合同编码：</label>
            <div class="col-sm-8">
                <input name="contractId" th:field="*{contractId}" class="form-control" type="text" readonly="readonly">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">合同开始时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="startTime" th:value="${#dates.format(tContract.startTime, 'yyyy-MM-dd')}"
                           class="form-control" placeholder="yyyy-MM-dd" type="text" readonly="readonly">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">合同结束时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="endTime" th:value="${#dates.format(tContract.endTime, 'yyyy-MM-dd')}"
                           class="form-control" placeholder="yyyy-MM-dd" type="text" readonly="readonly">
                </div>
            </div>
        </div>
        <!--        <div class="form-group">-->
        <!--            <label class="col-sm-3 control-label">合同扫描件：</label>-->
        <!--            <div class="col-sm-8">-->
        <!--                <input name="contractImg" th:field="*{contractImg}" class="form-control" type="text" required>-->
        <!--            </div>-->
        <!--        </div>-->
        <div class="form-group">
            <div class="left">
                <span class="red">*</span>
                <span class="col-sm-3 control-label">合同扫描件：</span>
            </div>
            <div class="input-group date">
                <img id="img" name="contractImg" class="img"
                     src="" th:src="${tContract.contractImg}"
                     alt="" width="50px" height="50px">
                <input type="file" onchange="fileupload(this)">
                <input type="hidden" id="contractImg" name="contractImg" value="">

            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">开户行：</label>
            <div class="col-sm-8">
                <input name="bank" th:field="*{bank}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">开户账号：</label>
            <div class="col-sm-8">
                <input name="bankNumber" th:field="*{bankNumber}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">手机号码：</label>
            <div class="col-sm-8">
                <input name="phone" th:field="*{phone}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">姓名：</label>
            <div class="col-sm-8">
                <input name="name" th:field="*{name}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">固定电话：</label>
            <div class="col-sm-8">
                <input name="telephone" th:field="*{telephone}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">邮箱：</label>
            <div class="col-sm-8">
                <input name="email" th:field="*{email}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">合同状态：</label>
            <div class="col-sm-8">
                <!--                <input name="state" th:field="*{state}" class="form-control" type="text" required>-->
                <label>
                    <select name="contractStart">
                        <option value="0">有效</option>
                        <option value="1">无效</option>
                        <option value="2">已过期</option>
                    </select>
                </label>

            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script type="text/javascript">
    var prefix = ctx + "mall/contract";
    $("#form-contract-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/renewContract", $('#form-contract-edit').serialize());
        }
    }

    $("input[name='startTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='endTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    function fileupload(e) {
        var fd = new FormData()
        fd.append('file', e.files[0])
        $.ajax({
            url: 'http://127.0.0.1:8007/common/fileUpload',
            type: 'POST',
            data: fd,
            processData: false,
            contentType: false,
            success: function (data) {
                console.log(data.url);
                $('#img').attr('src', data.url)
                $('#contractImg').attr("value", data.url)
            }
        })
    }
</script>
</body>
</html>